<template>
  <ul class="footer">
    <li @click="toIndex">
      <i class="fas fa-home"></i>
      <p>首页</p>
    </li>
    <li @click="toShoppingCart">
      <i class="fas fa-shopping-cart"></i>
      <p>购物车</p>
    </li>
    <li @click="toOrderList">
      <i class="fas fa-file-alt"></i>
      <p>订单</p>
    </li>
    <li @click="toUserProfile">
      <i class="fas fa-user"></i>
      <p>我的</p>
    </li>
  </ul>
</template>

<script setup>
import { useRouter, useRoute } from "vue-router";

const router = useRouter();
const route = useRoute();

// 获取用户角色
const getUserRole = () => {
  return sessionStorage.getItem('userRole') || 'USER';
};

function toIndex() {
  const userRole = getUserRole();
  if (userRole === 'BUSINESS') {
    router.push({ path: "/BusinessEnd" });
  } else {
    router.push({ path: "/index" });
  }
}

function toOrderList() {
  const userRole = getUserRole();
  if (userRole === 'BUSINESS') {
    router.push({ path: "/business-orders" });
  } else {
    router.push({ path: "/orderList" });
  }
}

function toUserProfile() {
  const userRole = getUserRole();
  if (userRole === 'BUSINESS') {
    router.push({ path: "/business-profile" });
  } else {
    router.push({ path: "/userProfile" });
  }
}

function toShoppingCart() {
  const userRole = getUserRole();
  if (userRole === 'BUSINESS') {
    // 商家没有购物车，跳转到首页
    router.push({ path: "/BusinessEnd" });
  } else {
    router.push({ path: "/shoppingCart" });
  }
}
</script>

<style scoped>
.footer {
  width: 100%;
  height: 14vw;
  border-top: solid 1px #ddd;
  background-color: #fff;
  position: fixed;
  left: 0;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 1000;
  margin: 0;
  padding: 0;
  list-style: none;
}

.footer li {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #999;
  user-select: none;
  cursor: pointer;
  flex: 1;
  height: 100%;
}

.footer li:hover {
  background-color: #f5f5f5;
}

.footer li p {
  font-size: 2.8vw;
  margin: 0;
  margin-top: 1vw;
}

.footer li i {
  font-size: 5vw;
}

/* 当前页面高亮显示 */
.footer li.router-link-active {
  color: #ee5a24;
}

.footer li.router-link-active p {
  color: #ee5a24;
}
</style>